<?php

namespace App\Http\Controllers;

use App\Common\Constant\Params;
use App\Libs\Filter\Filter;
use App\Services\IMasterService;
use Illuminate\Http\Request;

class MasterController extends BaseController
{
    /**
     * 所有师傅
     * @param Request $request
     */
    public function all(Request $request,IMasterService $masterServiceImpl)
    {
        $filter = Filter::instance()
            ->HTML('师傅姓名：')
            ->input('real_name')
            ->HTML('手机号码：')
            ->input('phone')
            ->HTML('所在省市区：')
            ->input('area_text')
            ->HTML('服务类型：')
            ->select('service_type',array(''=>'请选择')+Params::$SERVICE_TYPE,null,array('style'=>'width:150px'))
            ->br()->br()
            ->HTML('质保金：')
            ->select('assure_fund',array(''=>'请选择')+[0=>'未缴纳',1=>'已缴纳'],null,array('style'=>'width:150px'))
            ->HTML('入驻审核：')
            ->select('pass',array(''=>'请选择')+[Params::USER_STATUS_REVIEW=>'未审核',Params::USER_STATUS_NORMAL=>'已审核'],null,array('style'=>'width:150px'))
            ->HTML('停单操作：')
            ->select('disable',array(''=>'请选择')+[Params::USER_STATUS_NORMAL=>'未停单',Params::USER_STATUS_STOP=>'已停单'],null,array('style'=>'width:150px'))
            ->HTML('头像审核：')
            ->select('head_change_to',array(''=>'请选择')+[0=>'未审核',1=>'已审核'],null,array('style'=>'width:150px'))
            ->br()->br()
            ->HTML('入驻时间：')
            ->date('add_time')
            ->reset()->submit();
        if ($filter->is_filtering()){
            $list = $masterServiceImpl->all($filter->get_where());
        }else{
            $list = $masterServiceImpl->all();
        }
        return view('master/all',['list'=>$list,'filter'=>$filter,
            'disable_forever'=>Params::DISABLE_FOREVER,'disable_temporary'=>Params::DISABLE_TEMPORARY
        ]);
    }

    /**
     * 停单
     * @param Request $request
     * @return string
     */
    public function disable(Request $request,IMasterService $masterService)
    {
        if ($request->has('master_id') && $request->has('disable_type')){
            $masterService->disable($request->input('master_id'),$request->input('disable_type'),$request->input('disable_time'));
        }

        return back();
    }

    /**
     * 解除停单
     * @param Request $request
     * @return string
     */
    public function enable($master_id,Request $request,IMasterService $masterService)
    {
        $masterService->enable($master_id);
        return back();
    }

    /**
     * 通过注册申请并清缓存
     * @param Request $request
     * @return string
     */
    public function registerPass($master_id,Request $request,IMasterService $masterService)
    {
        $masterService->registerPass($master_id);
        return back();
    }

    /**
     * 头像通过审核并清缓存
     * @param Request $request
     * @return string
     */
    public function headimgPass($master_id,Request $request,IMasterService $masterService)
    {
        $masterService->headimgPass($master_id);
        return back();
    }

    /**
     * 删除师傅
     * @param Request $request
     * @return string
     */
    public function delMaster($master_id,Request $request,IMasterService $masterService)
    {
        $masterService->delete($master_id);
        return back();
    }
}
